redsleevefandomcom-20200215-history
Install on QNAP TS-421
Initialization Insert a 3.5" SATA disk complete the standard factory setup as per the instructions that came with your QNAP TS-421. This is done using it's web interface and will take a few minutes. Once this step is completed you should be able to ssh into it. The stock firmware's kernel version is 2.6.33.2 # uname -r 2.6.33.2 The SHA1 checksum of the kernel flash partition should be as follows: # cat /dev/mtdblock1 | sha1sum 6ff96114a82dd4864751329e2f2480a8085be6c7 - If these two don't match on your TS-421, it would probably be a good idea to seek help on the mailing list before you proceed. Retrieve Files From Standard Firmware You will need to acquire the following files from the standard firmware: Kernel modules: /lib/modules/{misc,local} Note: Make sure you get the actual files, not the symlinks pointing to those files, such as /lib/modules/other which points to /usr/local/modules. You will need to put these in /lib/modules/2.6.33.2/{misc,local} on your RedSleeve rootfs. Libraries: /lib/libiconv.so.2.2.0 /lib/libssl.so.1.0.0 /lib/libuLinux_ini.so /usr/lib/libcrypto.so.1.0.0 /usr/lib/libuLinux_ban.so.0.0 /usr/lib/libuLinux_cgi.so.0.0 /usr/lib/libuLinux_config.so.0.0 /usr/lib/libuLinux_ImR.so.0.0 /usr/lib/libuLinux_Ldap.so.0.0 /usr/lib/libuLinux_ms.so.1.0.0 /usr/lib/libuLinux_nasacl.so.1.0.0 /usr/lib/libuLinux_nasauth.so.1.0.0 /usr/lib/libuLinux_naslog.so.2.0.0 /usr/lib/libuLinux_naspriv.so.2.0.0 /usr/lib/libuLinux_NAS.so.0.0 /usr/lib/libuLinux_nvrlc.so.0.0 /usr/lib/libuLinux_nvrlog.so.2.0.0 /usr/lib/libuLinux_PDC.so.0.0 /usr/lib/libuLinux_qbox.so.2.0.0 /usr/lib/libuLinux_qlicense.so.0.0 /usr/lib/libuLinux_quota.so.0.0 /usr/lib/libuLinux_statistics.so.0.0 /usr/lib/libuLinux_Storage.so.0.0 /usr/lib/libuLinux_Util.so.0.0 You will need to copy these files into /usr/local/lib on your RedSleeve and place symlinks into /lib/ and /usr/lib/ folders as per the original locations listed above. Executables You will need at least the following: /sbin/get_time /sbin/lcd_tool /sbin/lcdmond /sbin/pic_raw Put these in /usr/local/sbin, and symlink get_time and lcd_tool to /sbin/ Extras for Further Investigation For completeness and further investigation later on, you may also want to copy across the following executables with all the symlinks pointig to them: aes config_util daemon_mgr daemon_mgr.nvr flv_convertd getcfg hotswap init_nic init_scsi_hd lcd_hwtest nasutil picd pic_dido pic_firmware_update pic_get_mac pic_get_sn pic_iface_get_mac pic_iface_set_mac pic_msg pic_rom pic_rw pic_set_mac pic_set_sn qwatchdogd rmcfg setcfg ubootcfg You can also put these in /usr/local/sbin/ Custom initramfs Unfortunately, the uboot parameters on the QNAP TS-421 are not fully adjustable - there are things that are hard-coded in uboot that override the settings stored in the uboot configuration flash segment. This, unfortunately, means we cannot change the uboot parameter that tells the kernel where to look for the rootfs. This isn't a show stopper - we just need a custom initrd that handles initial rootfs mounting. Here is the QNAP TS-421 custom initramfs I use. For the gory details you are encouraged to extract the initramfs and look at /init script. Investigating the Gory initramfs Details You can extract it as follows: gzip -cd QNAP_TS-421_initramfs-2.6.33.2.img | cpio -i In brief it does the following: 1) Assembles any MD arrays it finds (RAID 0/1/10 support is built into the stock kernel which is what we are using) 2) Looks for /sbin/init on present disks in the following order: md127, sda2, sdb2, sdc2, sdd2. The reason it looks for rootfs on the 2nd partition is purely a convention I use (partition 1 is either /boot or the zfs partition). Feel free to edit it if you prefer the initramfs to look on different partitions. 3) Once it finds /sbin/init, it disables the TS-421's build in watchdog (using pic_raw) and executes switch_root to hand over execution to init on the rootfs. If you are planning to edit the initrd, make sure you have wired up the serial console to your TS-421 so that you can get it booting again if you make a mistake. If you have edited the initrd, you can repack it using: find . | cpio -H newc -o | gzip -9 > mynewinitramfs.img You can burn this to the on-board flash using: dd if=mynewinitramfs.img of=/dev/mtdblock2.img ibs=9437184 obs=9437184 Note: The on-board watchdog gets enabled by uboot at boot time. This is one of those hard-coded options in uboot, and while you can change any options manually at boot time using the serial console for a single boot, they will not survive a reboot. The watchdog will automatically reboot the machine 5 minutes after booting up if it is not disabled, so it is vital we disable it during boot. Integrate rootfs Disk Preparation Put the disk you intend to use in a different machine. Make sure it has a suitably sized partition 2. If you are reading this wiki entry, it is assumed you are extremely comfortable with operations like this. Format partition 2 as ext4. Grab the current rootfs tarball and extract it to partition 2 you just formatted. Extra Files from Original Firmwre Take the files you copied from the stock firmware rootfs earlier and put it in the rootfs you just created: * Modules in /lib/modules/2.6.33.2/{misc,other}. * Libraries in /usr/local/lib/ with symlinks to /lib or /usr/lib as listed above. * Binaries in /usr/local/sbin/ with symlinks in /sbin for the two files mentioned above. Disable Virtual Terminal Consoles Disable virtual terminals since we have no frame buffer. In /etc/sysconfig/init (pseudo-diff): ACTIVE_CONSOLES= >#/dev/tty1-6 If you don't do this there will be unnecessary noise in syslog. Serial Console for Debugging Only If you are using the serial console, add this a file ttyS0.conf file to /etc/init/: # cat ttyS0.conf.bak start on stopped rc RUNLEVEL=2345 stop on starting runlevel 016 respawn pre-start exec /sbin/securetty ttyS0 exec /sbin/agetty -L /dev/ttyS0 115200 vt102 Note: DO NOT do this if you aren't using the serial console - this is only for debugging purposes and initial configuration as it requires the case to be removed. With the case removed there will be no airflow through the case and the disks and CPU are going to run much hotter than intended, so don't run the TS-421 without the case in normal operation. Ensure SSHD is Enabled Make sure ssh is enabled in the rootfs or you will not be able to log in: # ls -la /etc/rc3.d/*ssh* lrwxrwxrwx 1 root root 14 Feb 22 17:26 /etc/rc3.d/S55sshd -> ../init.d/sshd Network Configuration Make sure your network interface is configured appropriately or you will not be able to log in: # cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 BOOTPROTO=dhcp ONBOOT=yes DELAY=0 IPV6INIT=no IPV6_AUTOCONF=no NM_CONTROLLED=no LEDs, LCD Display, Fan Control Adjust rc.local with some useful things such as telling you what the IP address of eth0 is without having to look it up on your DHCP server: # cat /etc/rc.local touch /var/lock/subsys/local export PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin:/usr/local/bin # Status LED ON - Green pic_raw 86 # Configure LCD Display and Messages lcdmond lcd_tool -s 2 stty -F /dev/ttyS0 1200 sleep 1 echo -e "M^\x1" > /dev/ttyS0 sleep 1 echo -e "M\f\x0 Red Sleeve Linux" > /dev/ttyS0 sleep 1 ipaddr=`ifconfig eth0 | grep "inet addr:" | sed -e 's/.*inet addr://' -e 's/ .*//'` echo -e "M\f\x1 $ipaddr " > /dev/ttyS0 # Set fan to 4/5 speed (48:OFF 53:FULL) pic_raw 52 Enable Alignment Warnings and Configure MAC Addresses Set this to get warnings in the logs when alignment errors occur. Consider reporting a bug for these especially if they occur thousands of times in a frequently running program. # cat /etc/sysconfig/modules/alignment.modules #!/bin/bash echo 3 > /proc/cpu/alignment Note: The MACs here are made up, change them to what the label on the back of your NAS says. You can also get the MAC address of the primary interface using the "pic_get_mac" program copied from the stock firmware. The secondary interface's MAC is always adjecent and above the primary interface's MAC. # cat /etc/sysconfig/modules/eth.modules #!/bin/bash /sbin/ip link set dev eth0 address 00:11:22:33:44:55 /sbin/ip link set dev eth1 address 00:11:22:33:44:56 The Moment of Truth Finally, dd the initramfs you downloaded (and possibly modified as mentioned above) to /dev/mtdblock2.img: dd if=QNAP_TS-421_initramfs-2.6.33.2.img of=/dev/mtdblock2.img ibs=9437184 obs=9437184 Shut down the NAS and insert the disk you just prepared into the first slot. Power it up, and after a little while you should hear: * 1) A beep * 2) After a little while longer the status LED should go from flashing from red-green to solid green Once this happens, you should be able to ssh into the machine, and the IP address should show up on the LCD display. If this doesn't happen, hook up the serial console and investigate. Hooking up the Serial Console The instructions are available on Martin Michlmayr's site covering Debian on QNAP NAS systems. You will need a TTL to RS232 level shifter cable. The Raspberry Pi Console cable is suitable. Note: Make sure you connect the RX pin on the cable to the TX pin on the QNAP and vice versa. There is no need to connect the VCC pin so leave it off. If you are interested in more details on various intricacies of QNAP NAS-es and running non-standard Linux distributions on it, you may want to read through all the information on Martin's site. Other Useful Information Reference list of the known pic_raw op codes (some may not be applicable to TS-421): 48 Fan OFF 49 Fan Speed 1 50 Fan Speed 2 51 Fan Speed 3 52 Fan Speed 4 53 Fan Speed FULL 68 After Power Loss Go To Last State 76 (INT) Power LED Blink 77 (INT) Power LED ON 80 Silence Buzzer 81 Unsilence Buzzer 84 Status LED Blink RED Fast 85 Status LED Blink GREEN Fast 86 Status LED ON GREEN 87 Status LED ON RED 88 Status LED Blink GREEN/RED Fast 89 Status LED OFF 90 Status LED Blink GREEN Slow 91 Status LED Blink RED Slow 92 Status LED Blink GREEN/RED Fast 93 Status LED ON RED 99 10G Ethernet Extra 100 1G Ethernet Extra 103 WATCHDOG OFF 104 WATCHDOG ON, 5min REBOOT 105 WATCHDOG ON, 5min OFF 192 LED MODE (LOGO MODEL) 193 LED MODE (LOGO MODEL) 194 LED MODE (LOGO MODEL) 244 EUP OFF 245 EUP ON